ABC136 C - Build Stairs
https://atcoder.jp/contests/abc136/tasks/abc136_c
提出
code: python
n = int(input())
h = list(map(int, input().split()))
can = True
tmp = h0
for i in range(0, n-1):
if (hi < hi+1):
pass
else:
if (hi - 1 > hi+1):
can = False
break
if (hi - 1 == hi+1):
hi -= 1
if (can):
if (h == sorted(h)):
print("Yes")
else:
print("No")
else:
print("No")
解答
code: python
n = int(input())
h = list(map(int,input().split()))
# 初手は必ず−1しておいた方が有利
h0 -= 1
for i in range(1, n-1):
if hi > hi+1:
hi -= 1
# まだHi+1の方が小さければ不成立
if hi > hi+1:
print('No')
exit()
# Hiを1減らしたせいでHi-1の要素との関係が崩れていないか確認
if hi-1 > hi:
print('No')
exit()
# Hiから−1引いても大丈夫ならしておく
# これをしないと 1, 2, 2, 1 が Yes にならない
elif hi-1 <= hi-1:
hi -= 1
print('Yes')
code: python
n = int(input())
h = list(map(int, input().split()))
# 逆から見たら値を固定したまま検証できる
# 最小値を常に持って1引いても手前の数をその数以下にできない場合はNG
tmp = h-1
for i in range(n-1, 0, -1):
if (hi - 1 > tmp):
print("No")
exit()
tmp = min(tmp, hi)
print("Yes")
メモ
ABC136 C Build Stairs Python 3
ABC136 C問題 Build Stairs
提出
code: python
n = int(input())
h = list(map(int, input().split()))
# 山を削っていくイメージ
# maxの地点を求めると計算量
# 再帰的
提出
RE, WA
code: py
n = int(input())
h = list(map(int, input().split()))
# _
# _
# _ __
h1 = h:n//2
h2 = hn//2:
for i in range(1, n//2):
if h1i > h1i-1:
h1i -= 1
if h2i > h2i-1:
h2i -= 1
for i in range(1, n//2):
if h1i > h1i-1:
print("No")
exit()
if h2i > h2i-1:
print("No")
exit()
print("No") if h1-1 > h20 else print("Yes")